<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of tt_minres_selfprec</title>
  <meta name="keywords" content="tt_minres_selfprec">
  <meta name="description" content="Computation of the approximate TT-matrix inverse using self-prec method">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">exp</a> &gt; tt_minres_selfprec.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/exp&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>tt_minres_selfprec
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Computation of the approximate TT-matrix inverse using self-prec method</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [X]=tt_minres_selfprec(A, tol, eps, maxit, prec_type) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">Computation of the approximate TT-matrix inverse using self-prec method
   X=TT_MINRES_SELFPREC(A,TOL,EPS,MAXIT,PREC_TYPE) Computes the
   approximate matrix inverse of the TT-matrix A (given in TT1.0 format)


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>	Frobenius norm of the QTT-Tucker</li><li><a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>	Converts TT-matrix to TT1 cell-array format</li><li><a href="../../tt2/@tt_matrix/norm.html" class="code" title="function [nrm] = norm(t,varargin)">norm</a>	Matrix norm of the TT-matrix</li><li><a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>	Mode sizes of the TT-matrix</li><li><a href="../../tt2/@tt_tensor/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>	Converts TT-tensor TT1 to old-cell array format.</li><li><a href="../../tt2/@tt_tensor/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>	Frobenius norm of the TT-tensor</li><li><a href="../../tt2/@tt_tensor/size.html" class="code" title="function [sz] = size(tt,dim)">size</a>	Mode sizes of the TT-tensor</li><li><a href="../../tt2/core/tt_axpy.html" class="code" title="function [res]=tt_axpy(a, x, p, y, eps, max_rank)">tt_axpy</a>	Returns A*X+P*Y in the TT-format.</li><li><a href="../../tt2/core/tt_dot.html" class="code" title="function [res] = tt_dot(tt1,tt2)">tt_dot</a>	Scalar product of two TT-tensors in the TT1.0 format</li><li><a href="../../tt2/core/tt_eye.html" class="code" title="function [e]=tt_eye(n,varargin)">tt_eye</a>	Identity matrix in the TT-format</li><li><a href="../../tt2/core/tt_mat_compr.html" class="code" title="function [res]=tt_mat_compr(mat,eps, max_rank)">tt_mat_compr</a>	Tensor rounding for the TT-matrix in TT1.0 format</li><li><a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>	Flattens TT-matrix into TT-vector in the TT1.0 format</li><li><a href="../../tt2/core/tt_mm.html" class="code" title="function [res]=tt_mm(mat1,mat2)">tt_mm</a>	Matrix-by-matrix product in TT1.0 format</li><li><a href="../../tt2/core/tt_ranks.html" class="code" title="function [rks]=tt_ranks(tt)">tt_ranks</a>	Compute all ranks of the TT-decomposition in TT1.0 format</li><li><a href="../../tt2/core/tt_scal.html" class="code" title="function [res] = tt_scal(tt,alpha)">tt_scal</a>	Multiply tensor by a scalar in TT1.0 format</li><li><a href="../../tt2/core/tt_size.html" class="code" title="function [sz]=tt_size(tt)">tt_size</a>	Mode dimensions of a TT-tensor in TT1.0 format</li><li><a href="../../tt2/core/tt_transp.html" class="code" title="function [tt]=tt_transp(tt)">tt_transp</a>	Transposition of the TT matrix</li><li><a href="../../tt2/core/tt_vec_to_mat.html" class="code" title="function [tt_mat]=tt_vec_to_mat(tt_vec,n,m)">tt_vec_to_mat</a>	Converts TT-vector to TT-matrix in TT1.0 format</li><li><a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>	DMRG/Krylov matrix-by-matrix multiplication</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/solve/dmrg_solve2.html" class="code" title="function [x, sweeps]=dmrg_solve2(A, y, eps,varargin)">dmrg_solve2</a>	Solution of linear systems in TT-format via DMRG iteration</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [X]=tt_minres_selfprec(A, tol, eps, maxit, prec_type)</a>
0002 <span class="comment">%Computation of the approximate TT-matrix inverse using self-prec method</span>
0003 <span class="comment">%   X=TT_MINRES_SELFPREC(A,TOL,EPS,MAXIT,PREC_TYPE) Computes the</span>
0004 <span class="comment">%   approximate matrix inverse of the TT-matrix A (given in TT1.0 format)</span>
0005 <span class="comment">%</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0008 <span class="comment">%</span>
0009 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0010 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0011 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0012 <span class="comment">%</span>
0013 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0014 <span class="comment">%ivan.oseledets@gmail.com</span>
0015 <span class="comment">%---------------------------</span>
0016 
0017 matvec=<span class="string">'mm+compr'</span>;
0018 max_rank=10;
0019 
0020 d=max(<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(A));
0021 ns=<a href="../../tt2/core/tt_size.html" class="code" title="function [sz]=tt_size(tt)">tt_size</a>(A);
0022 
0023 I=<a href="../../tt2/core/tt_eye.html" class="code" title="function [e]=tt_eye(n,varargin)">tt_eye</a>(ns, d); I=<a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>(I); 
0024 <span class="keyword">if</span> (strcmp(prec_type, <span class="string">'left'</span>))
0025     X=<a href="../../tt2/core/tt_scal.html" class="code" title="function [res] = tt_scal(tt,alpha)">tt_scal</a>(<a href="../../tt2/core/tt_transp.html" class="code" title="function [tt]=tt_transp(tt)">tt_transp</a>(A), 1e-15);
0026 <span class="keyword">else</span>
0027     X=<a href="../../tt2/core/tt_scal.html" class="code" title="function [res] = tt_scal(tt,alpha)">tt_scal</a>(I, 1e-150);
0028 <span class="keyword">end</span>;
0029 
0030 normf=sqrt(<a href="../../tt2/core/tt_dot.html" class="code" title="function [res] = tt_dot(tt1,tt2)">tt_dot</a>(<a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(I), <a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(I)));
0031 err=1;
0032 err_old=2;
0033 sp=0;
0034 
0035 <span class="keyword">for</span> iout=1:maxit
0036     <span class="keyword">if</span> (strcmp(matvec, <span class="string">'mmk2'</span>))
0037         resid=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(A, X, eps, max_rank);
0038     <span class="keyword">else</span>
0039         resid=<a href="../../tt2/core/tt_mm.html" class="code" title="function [res]=tt_mm(mat1,mat2)">tt_mm</a>(A,X);
0040         resid=<a href="../../tt2/core/tt_mat_compr.html" class="code" title="function [res]=tt_mat_compr(mat,eps, max_rank)">tt_mat_compr</a>(resid, eps,max_rank*2);
0041     <span class="keyword">end</span>;
0042     resid=ttm_add(I, <a href="../../tt2/core/tt_scal.html" class="code" title="function [res] = tt_scal(tt,alpha)">tt_scal</a>(resid, -1));
0043     
0044     
0045     <span class="keyword">if</span> (iout&gt;1)||(strcmp(prec_type, <span class="string">'left'</span>))
0046         <span class="keyword">if</span> (strcmp(matvec, <span class="string">'mmk2'</span>))
0047             Xresid=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(X, resid, eps,max_rank);
0048         <span class="keyword">else</span>
0049             Xresid=<a href="../../tt2/core/tt_mm.html" class="code" title="function [res]=tt_mm(mat1,mat2)">tt_mm</a>(X,resid);
0050             Xresid=<a href="../../tt2/core/tt_mat_compr.html" class="code" title="function [res]=tt_mat_compr(mat,eps, max_rank)">tt_mat_compr</a>(Xresid, eps,max_rank*2);
0051         <span class="keyword">end</span>;
0052     <span class="keyword">else</span>
0053         Xresid=resid;
0054     <span class="keyword">end</span>;
0055     
0056     max_xrrank=max(<a href="../../tt2/core/tt_ranks.html" class="code" title="function [rks]=tt_ranks(tt)">tt_ranks</a>(<a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(Xresid)));
0057     
0058     <span class="keyword">if</span> (strcmp(prec_type, <span class="string">'left'</span>)) <span class="comment">% we use left preconditioner (igmres)</span>
0059         <span class="keyword">if</span> (strcmp(matvec, <span class="string">'mmk2'</span>))
0060             w=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(A, Xresid, eps,max_rank);
0061             w=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(X, w, eps,max_rank);
0062         <span class="keyword">else</span>
0063             w=<a href="../../tt2/core/tt_mm.html" class="code" title="function [res]=tt_mm(mat1,mat2)">tt_mm</a>(A,Xresid);
0064             w=<a href="../../tt2/core/tt_mat_compr.html" class="code" title="function [res]=tt_mat_compr(mat,eps, max_rank)">tt_mat_compr</a>(w, eps,max_rank);
0065             w=<a href="../../tt2/core/tt_mm.html" class="code" title="function [res]=tt_mm(mat1,mat2)">tt_mm</a>(X,w);
0066 <span class="comment">%             w=tt_mat_compr(w, eps);</span>
0067         <span class="keyword">end</span>;
0068         
0069         w = <a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(w);        
0070         beta=sqrt(<a href="../../tt2/core/tt_dot.html" class="code" title="function [res] = tt_dot(tt1,tt2)">tt_dot</a>(<a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(Xresid),<a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(Xresid)));
0071         wr = <a href="../../tt2/core/tt_dot.html" class="code" title="function [res] = tt_dot(tt1,tt2)">tt_dot</a>(w, <a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(Xresid));
0072         ww = <a href="../../tt2/core/tt_dot.html" class="code" title="function [res] = tt_dot(tt1,tt2)">tt_dot</a>(w,w); 
0073         
0074         H=zeros(2,1);
0075         H(1,1)=wr/(beta^2);
0076         H(2,1)=sqrt(ww/(beta^2)-wr^2/(beta^4));
0077         rhs=H(1,1)*beta;
0078         
0079         y = rhs/(H'*H);
0080         err = err*<a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(H*y-[beta; 0])/beta; 
0081         y=y/beta;
0082         
0083 <span class="comment">%         y = tt_dot(w,w);</span>
0084 <span class="comment">%         if (y~=0)</span>
0085 <span class="comment">%             y = tt_dot(w, tt_mat_to_vec(Xresid))/y;</span>
0086 <span class="comment">%         else</span>
0087 <span class="comment">%             y=1;</span>
0088 <span class="comment">%         end;</span>
0089     <span class="keyword">else</span> <span class="comment">% Use right preconditioner and fgmres</span>
0090         <span class="keyword">if</span> (strcmp(matvec, <span class="string">'mmk2'</span>))
0091             w=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(A, Xresid, eps,max_rank);
0092         <span class="keyword">else</span>
0093             w=<a href="../../tt2/core/tt_mm.html" class="code" title="function [res]=tt_mm(mat1,mat2)">tt_mm</a>(A,Xresid);
0094 <span class="comment">%             w=tt_mat_compr(w, eps);</span>
0095         <span class="keyword">end</span>;
0096         
0097         w = <a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(w);        
0098         
0099         beta=sqrt(<a href="../../tt2/core/tt_dot.html" class="code" title="function [res] = tt_dot(tt1,tt2)">tt_dot</a>(<a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(resid),<a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(resid)));
0100         wr = <a href="../../tt2/core/tt_dot.html" class="code" title="function [res] = tt_dot(tt1,tt2)">tt_dot</a>(w, <a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(resid));
0101         ww = <a href="../../tt2/core/tt_dot.html" class="code" title="function [res] = tt_dot(tt1,tt2)">tt_dot</a>(w,w); 
0102         
0103         H=zeros(2,1);
0104         H(1,1)=wr/(beta^2);
0105         H(2,1)=sqrt(ww/(beta^2)-wr^2/(beta^4));
0106         rhs=H(1,1)*beta;
0107         
0108         y = rhs/(H'*H);
0109         err = <a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(H*y-[beta; 0])/normf; 
0110         y=y/beta;
0111         
0112 <span class="comment">%         y2=ww;</span>
0113 <span class="comment">%         if (y~=0)</span>
0114 <span class="comment">%             y2 = wr/y2;</span>
0115 <span class="comment">%         else</span>
0116 <span class="comment">%             y2=1;</span>
0117 <span class="comment">%         end;</span>
0118     <span class="keyword">end</span>;
0119     
0120     max_wrank=max(<a href="../../tt2/core/tt_ranks.html" class="code" title="function [rks]=tt_ranks(tt)">tt_ranks</a>(w));
0121                 
0122     Xresid=<a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(Xresid);    
0123     
0124     X=<a href="../../tt2/core/tt_mat_to_vec.html" class="code" title="function [tt_vec]=tt_mat_to_vec(tt_mat)">tt_mat_to_vec</a>(X);
0125     <span class="keyword">if</span> (err&lt;err_old)
0126         X = <a href="../../tt2/core/tt_axpy.html" class="code" title="function [res]=tt_axpy(a, x, p, y, eps, max_rank)">tt_axpy</a>(1, X, y, Xresid, eps, max_rank);
0127         err_old=err;
0128     <span class="keyword">else</span>
0129         sp=sp+1;
0130     <span class="keyword">end</span>;
0131     max_xrank=max(<a href="../../tt2/core/tt_ranks.html" class="code" title="function [rks]=tt_ranks(tt)">tt_ranks</a>(X));
0132     
0133     X = <a href="../../tt2/core/tt_vec_to_mat.html" class="code" title="function [tt_mat]=tt_vec_to_mat(tt_vec,n,m)">tt_vec_to_mat</a>(X, ns, ns);
0134     
0135 <span class="comment">%     if (strcmp(matvec, 'mmk2'))</span>
0136 <span class="comment">%         resid=tt_mmk2(A, X, eps, max_rank);</span>
0137 <span class="comment">%     else</span>
0138 <span class="comment">%         resid=tt_mm(A, X);</span>
0139 <span class="comment">% %         resid=tt_mat_compr(resid, eps);</span>
0140 <span class="comment">%     end;</span>
0141 <span class="comment">%     resid=ttm_add(I, tt_scal(resid, -1));</span>
0142 <span class="comment">%     resid=tt_mat_to_vec(resid);</span>
0143 <span class="comment">%</span>
0144 <span class="comment">%     err_real=sqrt(tt_dot(resid,resid))/normf;</span>
0145     err_real=0;
0146     fprintf(<span class="string">'iter [%d], res_real=%3.3e, x_rank=%d, Xr_rank=%d, w_rank=%d, err=%3.3e\n'</span>, iout, err_real, max_xrank, max_xrrank, max_wrank, err);    
0147     <span class="keyword">if</span> (err&lt;tol)||(sp&gt;0)
0148         <span class="keyword">break</span>;
0149     <span class="keyword">end</span>;
0150     
0151 <span class="keyword">end</span>;
0152 
0153 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>